﻿using FNN.Helpers.DataSource;
using FNN.NetworkMasters;
using FNN.Networks;
using System;
using System.Configuration;

namespace FNN.Factories.Networks
{
    public class NetworkMasterFactory
    {
        private DataSourceHelper _helper;

        public NetworkMasterFactory(DataSourceHelper helper)
        {
            _helper = helper;
        }

        public NetworkMaster CreateMaster(NetworkTypes networkType)
        {
            var defaultPopulationCount = Convert.ToInt32(ConfigurationManager.AppSettings["defaultPopulationCount"]);

            NetworkMaster result = null;
            switch (networkType)
            {
                case NetworkTypes.Financial:
                    var financialMaster = new FinancialNetworkMaster()
                    {
                        PopulationCount = defaultPopulationCount,
                        DataSource = _helper.GetDataSource(),
                        GeneticIterationsLimit = 1000,
                        GeneticTimeLimit = 12,
                        GeneticTargetResult = 0,
                        IterationsLimit = 1000,
                        TargetResult = 0,
                        TimeLimit = 12
                    };
                    break;
                case NetworkTypes.Regular:
                    var regularMaster = new RegularNetworkMaster()
                    {
                        PopulationCount = defaultPopulationCount,
                        DataSource = _helper.GetDataSource(),
                        GeneticIterationsLimit = 1000,
                        GeneticTimeLimit = 12,
                        TargetResult = -1,
                        IterationsLimit = 1000,
                        TimeLimit = 12
                    };
                    break;
                default:
                    throw new ArgumentOutOfRangeException("networkType", "Unknown network type!");
            }
            return result;
        }
    }
}
